package com.cnd.scm.orm.repositoryproxy;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

/**
 * @version V1.0
 * @ClassName: PhoenixRepositoryProxyFactoryBean
 * @Description:
 * @author: 李启联
 * @date: 2020-05-29 11:52
 * @Copyright: Copyright (c), 2020
 */
public class PhoenixRepositoryProxyFactoryBean<T> implements FactoryBean {


    //被代理的接口Class对象
    private Class<T> interfaceClass;


    public PhoenixRepositoryProxyFactoryBean(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }


    @Override
    public T getObject() throws Exception {
        //通过JDK动态代理创建代理类
        return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[]{interfaceClass},
                new PhoenixRepositoryProxy<>(interfaceClass));
    }

    @Override
    public Class<?> getObjectType() {
        return interfaceClass;
    }

}